1 using UnityEngine;
2 using
System.Collections;
3
4 namespace
Completed
5 {
6     
public class Wall : MonoBehaviour
7     {
8         
public AudioClip chopSound1; //1 of 2 audio clips that play when the wall is attacked by the player.
9         
public AudioClip chopSound2; //2 of 2 audio clips that play when the wall is attacked by the player.
10         
public Sprite dmgSprite; //Alternate sprite to display after Wall has been attacked by player.
11         
public int hp = 3; //hit points for the wall.
12         
13         
14         
private SpriteRenderer spriteRenderer; //Store a component reference to the attached SpriteRenderer.
15         
16         
17         
void Awake ()
18         {
19             
//Get a component reference to the SpriteRenderer.
20             spriteRenderer = GetComponent<SpriteRenderer> ();
21         }
22         
23         
24         
//DamageWall is called when the player attacks a wall.
25         
public void DamageWall (int loss)
26         {
27             
//Call the RandomizeSfx function of SoundManager to play one of two chop sounds.
28             SoundManager.instance.RandomizeSfx (chopSound1, chopSound2);
29             
30             
//Set spriteRenderer to the damaged wall sprite.
31             spriteRenderer.sprite = dmgSprite;
32             
33             
//Subtract loss from hit point total.
34             hp -= loss;
35             
36             
//If hit points are less than or equal to zero:
37             
if(hp <= 0)
38                 
//Disable the gameObject.
39                 gameObject.SetActive (
false);
40         }
41     }
42 }


public AudioClip chopSound1; 1 of 2 audio clips that play when the wall is attacked by the player.

public AudioClip chopSound2; 2 of 2 audio clips that play when the wall is attacked by the player.

public Sprite dmgSprite; Alternate sprite to display after Wall has been attacked by player.

public int hp = 3; hit points for the wall.

private SpriteRenderer spriteRenderer; Store a component reference to the attached SpriteRenderer.

Get a component reference to the SpriteRenderer.

DamageWall is called when the player attacks a wall.

Call the RandomizeSfx function of SoundManager to play one of two chop sounds.

Set spriteRenderer to the damaged wall sprite.

Subtract loss from hit point total.

If hit points are less than or equal to zero:

Disable the gameObject.




Trò chơi giống như Rogue 2D sử dụng Unity 28.441 lượt xem

Gõ tìm kiếm nhanh...